﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ThermalEquipmentDesign.Model;
using System.Collections.ObjectModel;
using Com.DA;
using Com;
using Com.BU;
using System.Windows;


namespace ThermalEquipmentDesign.Model.CoolingTower
{
    public class CoolingTower : ObservableObject
    {

        // Declare fields for inputting
        #region Feild input
        private double dbairTemp;
        private double dbaverageMoisture;
        private double dbaverageTempMax;
        private double dbcondenserCalory;
        private double dbcoolingCapacity;
        private double dbcoolingWaterFlow;
        private double dbcorrectionFactor;
        private double dbmaxTempe;
        private double dboutWaterTemp;
        private double dbwaterTemp;
        private double dbrefrigerantTemp;
        private double dbtempeWet; 
        #endregion

        // Create properties for fields
        #region properties
        private ObservableCollection<tb_location> Location = LibraryManagerInCom.LocationList;
        private tb_location slocation;

        public tb_location sLocation
        {
            get { return slocation; }
            set
            {
                slocation = value;
                loadTemperHumid();
            }
        }
        public ObservableCollection<tb_location> Location1
        {
            get { return Location; }
            set
            {
                Location = value;
            }
        }
        //List<string> weather = new List<string>()
        //{
        //     "Summer","Winter"
            
        //};
        //public List<string> Weather
        //{
        //    get { return weather; }
        //    set { weather = value; }

        //}

       
        public double DbAirTemp
        {
            get { return dbairTemp; }
            set { dbairTemp = value; }
        }
       

        public double DbAverageMoisture
        {
            get { return dbaverageMoisture; }
            set { dbaverageMoisture = value; }
        }
        

        public double DbAverageTempMax
        {
            get { return dbaverageTempMax; }
            set { //dbaverageTempMax = value;
            if (value != dbaverageTempMax)
            {
                dbaverageTempMax = value;
                dbaverageTempMax = value;
                loadair();

            }
            }
        }
        

        public double DbCondenserCalory
        {
            get { return dbcondenserCalory; }
            set {
            if (value != dbcondenserCalory)
            {
                dbcondenserCalory = value;
                dbcoolingWaterFlow = (dbcondenserCalory / 20950)*60000;

                OnPropertyChanged("DbCondenserCalory");
            }
            }

        }
        
        public double DbCoolingCapacity
        {
            get { return dbcoolingCapacity; }
            set { dbcoolingCapacity = value;
            
            }

        }
    

        public double DbCoolingWaterFlow
        {
            get { return dbcoolingWaterFlow; }
            set { dbcoolingWaterFlow = value; }
        }
        
        public double DbCorrectionFactor
        {
            get { return dbcorrectionFactor; }
            set { 
            if (value != dbcorrectionFactor)
            {
               
                dbcorrectionFactor = value;
                dbcoolingCapacity = dbcondenserCalory / dbcorrectionFactor;
                OnPropertyChanged("DbCorrectionFactor");
            }
            }
        }
        

        public double DbMaxTempe
        {
            get { return dbmaxTempe; }
            set { //dbmaxTempe = value;
                if (value != dbmaxTempe)
            {
                dbmaxTempe = value;
                loadair();
                
            }
            }
        }
        
        public double DbOutWaterTemp
        {
            get { return dboutWaterTemp; }
            set { dboutWaterTemp = value; }
        }
       
        public double DbWaterTemp
        {
            get { return dbwaterTemp; }
            set { dbwaterTemp = value; }
        }
        
        public double DbRefrigerantTemp
        {
            get { return dbrefrigerantTemp; }
            set { dbrefrigerantTemp = value; }
        }
       

        public double DbTempeWet
        {
            get { return dbtempeWet; }
            set
            {
                if (value != dbtempeWet)
                {
                    dbtempeWet = value;
                    Loadwatertempe();
                }
            }
        }


        #endregion
        /// <summary>
        /// Calculate Airtemperature
        /// </summary>
        private void loadTemperHumid()
        {
            dbaverageTempMax = (double)slocation.average_temperature;
            OnPropertyChanged("DbAverageTempMax");
            dbmaxTempe = (double)slocation.max_temperature;
            OnPropertyChanged("DbMaxTempe");
            dbaverageMoisture = (double)slocation.max_humidity;
            OnPropertyChanged("DbAverageMoisture");
            dbairTemp = (dbaverageTempMax + dbmaxTempe) / 2;
            OnPropertyChanged("DbAirTemp");

        }
        /// <summary>
        /// Load in water temperature and out water temperature
        /// </summary>
        private void Loadwatertempe()
        {
            dbwaterTemp = dbtempeWet + 5;
            OnPropertyChanged("DbWaterTemp");
            dboutWaterTemp = dbwaterTemp + 5;
            OnPropertyChanged("DbOutWaterTemp");
           
        }
        private void loadair()
        {
            dbairTemp = (dbaverageTempMax + dbmaxTempe) / 2;
            OnPropertyChanged("DbAirTemp");
        }
     

    }
}
